/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Interface;

import Biz.StaffBO;
import Biz.TestBO;
import Entity.Staff;
import Entity.Test;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.AbstractTableModel;
import javax.swing.text.View;

/**
 *
 * @author Nghia
 */
public class Model_Staff extends AbstractTableModel {

    protected String[] columnNames;
    protected ArrayList employeeList;
    protected java.util.List<Staff> staffList;
    protected java.util.List<Staff> staffListDetail;

    public Model_Staff() {
    }

    public Model_Staff(String[] columnNames, java.util.List<Staff> staffList) throws SQLException {
        this.columnNames = columnNames;
        this.staffList = staffList;
        this.staffListDetail = new StaffBO().getStaff();

    }

    @Override
    public String getColumnName(int i) {
        return columnNames[i];
    }

    @Override
    public Class getColumnClass(int column) {
        switch (column) {
            case 0:
                return Integer.class;
            case 1:
                return String.class;
            case 2:
                return Boolean.class;
            case 3:
                return String.class;
            case 4:
                return String.class;
            case 5:
                return Boolean.class;
            default:
                return String.class;
        }
    }

    @Override
    public void setValueAt(Object value, int row, int column) {
        Staff e = (Staff) staffList.get(row);
        switch (column) {
            case 0:
                e.setStaffID((Integer) value);
            case 1:
                e.setFName(String.valueOf(value));
            case 2:
                e.setGender((Boolean) value);
            case 3:
                e.setDOJ((Date) value);
            case 4:
                e.setUsername(String.valueOf(value));
            case 5:
                e.setStatus((Boolean) value);
            default:
                System.out.println("Invalid index");
        }
        fireTableCellUpdated(row, column);
    }

    @Override
    public int getRowCount() {
        return staffList.size();
    }

    @Override
    public int getColumnCount() {
        return columnNames.length;
    }

    @Override
    public Object getValueAt(int row, int column) {
        Staff s = (Staff) staffList.get(row);
        switch (column) {
            case 0:
                return s.getStaffID();
            case 1:
                return s.getFName();
            case 2:
                return s.isGender();
            case 3:
                return s.getDOJ();
            case 4:
                return s.getUsername();
            case 5:
                return s.isStatus();
            default:
                return new Object();
        }
    }

    public void add(String FName, String LName, Date DOJ, String Dept, String Address, int P_No, boolean Gender, Date DOB, String Edu_qual, String Tech_Skills, String Username, String Password, boolean Status) throws ClassNotFoundException, SQLException, Exception {
        StaffBO sb = new StaffBO();
        try {
            sb.addStaff(FName, LName, DOJ, Dept, Address, P_No, Gender, DOB, Edu_qual, Tech_Skills, Username, Password, Status);
        } catch (SQLException ex) {
            Logger.getLogger(View.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void edit(int StaffID, String FName, String LName, Date DOJ, String Dept, String Address, int P_No, boolean Gender, Date DOB, String Edu_qual, String Tech_Skills, boolean Status) throws ClassNotFoundException, SQLException, Exception {
        StaffBO sb = new StaffBO();
        try {
            sb.editStaff(StaffID, FName, LName, DOJ, Dept, Address, P_No, Gender, DOB, Edu_qual, Tech_Skills, Status);
        } catch (SQLException ex) {
            Logger.getLogger(View.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
